package com.dao.Impl;

import com.dao.UserDao;
import com.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public User SelectUserByUsername(String username) {
        String sql="select * from user where username=?";
        try {
            User user = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), username);
            return user;
        }catch (Exception e){
            return null;
        }
    }

    public int addUser(String username, String password, String touxiang) {
        String sql="insert into user (username,password,touxiang) values (?,?,?)";
        int i = jdbcTemplate.update(sql, username, password, touxiang);
        return i;
    }

    public int updPassword(String username, String password) {
        return 0;
    }
}
